var api = require("../../utils/api.js");
Page({
  data: {
    hidden1: false,
    hidden2: true,
    hidden3: true,
    applyList: [],
    // 验证码输入框
    codeInputValue: "",
    userInfo: [],
    breakContractEmail: "",
    breakContractPhone: "",
    agreementOpened: true,
    askOpened: true,
    taskId: ""
  },
  onLoad: function (options) {
    api.client.listTasksByLiableUserId(function (res) {}, this);
  },
  onReady: function () {},
  onShow: function () {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    api.client.listTasksByLiableUserId(function (res) {}, this);
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {},
  // 查看公证书
  see_book(event) {
    console.log('see_book');
    var id = event.currentTarget.id;
    // 打开查看公证书
    wx.downloadFile({
      url: 'https://fq.turingsingularity.com/downfile/group1/yxfq_8c4ce7326f0d4f6aa5c419e0fd84464c/' + this.data.applyList[id].id + '_公证书.pdf',
      // url: "http://122.112.193.203:3666/group1/yxfq_8c4ce7326f0d4f6aa5c419e0fd84464c/8c4ce7326f0d4f6aa5c419e0fd84464c0a2bdb6b-c4d4-11ea-a213-0242ac11000c_a7621546-eb2b-4fcb-b8ef-96273fc59cf3_公证申请表.pdf",
      success: function (res) {
        const filePath = res.tempFilePath
        wx.openDocument({
          filePath: filePath,
          success: function (res) {
            console.log('打开文档成功')
          }
        });
      }
    });
  },
  // 打开授权对话框
  apply(event) {
    var id = event.currentTarget.id;
    if (this.data.applyList[id].operationStatus == "申 请") {
      wx.setStorageSync('enquireMethod', this.data.applyList[id].enquireMethod);
      api.client.getUserByUserInfoUserId(function (res) {}, this.data.applyList[id].id, this);
    } else {
      // 进入查看申请页面
      wx.navigateTo({
        url: "../../pages/checkApply/checkApply?taskId=" + this.data.applyList[id].id
      });
    }
  },
  checkboxOnChange(e) {
    if (e.detail.value == "选中") {
      this.setData({
        check: true
      });
    } else {
      this.setData({
        check: false
      });
    }
  },
  // 点击打开安心签服务平台协议
  agreement() {
    wx.navigateTo({
      url: "../../pages/agreement/agreement"
    });
  },
  getCode() {
    api.client.electronicSignatureAuthorize(function (res) {}, this);
  },
  codeInput(e) {
    this.setData({
      codeInputValue: e.detail.value
    });
  },
  // 进入申请页面
  submit() {
    if (this.data.codeInputValue == null || this.data.codeInputValue == "") {
      wx.showToast({
        title: "验证码不能为空",
        icon: 'none',
        duration: 2000
      });
    } else {
      api.client.authorizeCheck(function (res) {}, this.data.codeInputValue, this);
    }
  },
  // 电子签名对话框取消
  agreementCancel() {
    this.setData({
      agreementOpened: true
    });
  },
  // 进入书面询问页面
  paperAsk(event) {
    var id = event.currentTarget.id;
    if (this.data.applyList[id].paperAskColor == "#1C6FFF") {
      if (this.data.applyList[id].enquireMethod == "书面询问") {
        wx.navigateTo({
          url: "../../pages/paperAsk/paperAsk?taskId=" + this.data.applyList[id].id
        });
      } else {
        // 打开在线询问对话框
        this.setData({
          askOpened: false,
          taskId: this.data.applyList[id].id
        });
      }
    }
  },
  online_submit() {
    this.setData({
      askOpened: true
    });
    wx.navigateTo({
      url: "../../pages/online/online?taskId=" + this.data.taskId
    });
  },
  cancel() {
    this.setData({
      askOpened: true
    });
  },
  // 进入支付页面
  pay() {
    wx.navigateTo({
      url: "../../pages/pay/pay"
    });
  },
  // 进入消息页面
  message() {
    wx.navigateTo({
      url: "../../pages/message/message"
    });
  },
  // 点击下面的tab
  tab1() {
    this.setData({
      hidden1: false,
      hidden2: true,
      hidden3: true
    });
    wx.setNavigationBarTitle({
      title: '公证申请',
    });
    api.client.listTasksByLiableUserId(function (res) {}, this);
  },
  tab2() {
    this.setData({
      hidden1: true,
      hidden2: false,
      hidden3: true
    });
    wx.setNavigationBarTitle({
      title: '账单',
    });
    // api.client.getCollectionList(function (res) {}, this);
  },
  tab3() {
    this.setData({
      hidden1: true,
      hidden2: true,
      hidden3: false
    });
    wx.setNavigationBarTitle({
      title: '我的',
    });
    api.client.listUsersByUserInfoUserId(function (res) {}, this);
    api.client.getBreakContractReceivingMeans(function (res) {}, this);
  },
})